﻿using UnityEngine;
using System.Collections;

public sealed class MusicPlayer : MonoBehaviour
{
    int screenWidth;
    int screenHeight;
    public string musicToPlay = "";

    void Start()
    {
        screenWidth = Screen.currentResolution.width;
        screenHeight = Screen.currentResolution.height;
    }

    void PlayMusic(string songName)
    {
        if (songName != musicToPlay)
            return;

        if (!audio.isPlaying)
        {
            audio.clip = Resources.Load(musicToPlay, typeof(AudioClip)) as AudioClip;
            if (audio.clip == null)
            {
                Controller.SetMessage("Cannot load file \"Resources/" + musicToPlay + "\"");
            }
            else
            {
                audio.Play();
                Screen.SetResolution(screenWidth, screenHeight, true);
            }
        }
        else
        {
            audio.Stop();
            Screen.SetResolution(640, 480, false);
        }
    }
}
